﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Indie_Game_Contest
{
    class GameControlState : IGameState
    {
        //////////////////////////////////////////////////////////////////////////
        // Data Members
        static GameControlState instance = new GameControlState();
        int fontID;
        int wID;
        int aID;
        int sID;
        int dID;
        int fightID;

        private int m_nCurrentButton = -1;



        //////////////////////////////////////////////////////////////////////////
        // Methods
        public override void Update(float dt)
        {
            IntroState.Instance.Cat.Update(10);
            //IntroState.Instance.Cat.
        }
        public override bool Input()
        {
            if (CInput.Instance.KeyPressed(Keys.Enter) || CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                Game1.Instance.AddState(GameplayState.Instance);
                Game1.Instance.RemoveState(this);
                return true;
            }
            else if (CInput.Instance.KeyPressed(Keys.Escape) || CInput.Instance.GamePadButtonPressed(Buttons.B))
            {
                Game1.Instance.AddState(MainMenuSate.Instance);
                Game1.Instance.RemoveState(this);
                return true;
            }

            if (CInput.Instance.KeyDown(Keys.Left) || CInput.Instance.KeyDown(Keys.A))
            {
                IntroState.Instance.Flip = true;
                NCurrentButton = 1;
                return true;
            }
            if (CInput.Instance.KeyDown(Keys.Right) || CInput.Instance.KeyDown(Keys.D))
            {
                if (IntroState.Instance.Flip)
                    IntroState.Instance.Flip = false;
                NCurrentButton = 2;
                return true;
            }

            if (CInput.Instance.KeyDown(Keys.Up) || CInput.Instance.KeyDown(Keys.W))
            {
                NCurrentButton = 3;
                return true;
            }

            if (CInput.Instance.KeyDown(Keys.Space) )
            {
                NCurrentButton = 4;
                return true;
            }

            NCurrentButton = -1;
            return true;
        }
        public override void Render()
        {
            WorldData.spriteBatch.Draw(TextureManager.Instance.GetTexture(CTileManager.Instance.TileIDs["curtains"]),
                 new Rectangle(-15, 0, WorldData.WindowWidth + 30, WorldData.WindowHeight + 25), Color.White);

            SpriteFont font = TextureManager.Instance.GetSpriteFont(fontID);

            WorldData.spriteBatch.DrawString(font,"CONTROLS", new Vector2(WorldData.WindowWidth / 2 - 4 * 24, 10), Color.SkyBlue);

            Texture2D w = TextureManager.Instance.GetTexture(wID);
            Texture2D a = TextureManager.Instance.GetTexture(aID);
            Texture2D s = TextureManager.Instance.GetTexture(sID);
            Texture2D d = TextureManager.Instance.GetTexture(dID);
            Vector2 aPos = new Vector2(WorldData.WindowWidth / 2 - 100, 325);
            Vector2 dPos = new Vector2(WorldData.WindowWidth / 2 + 50, 325);
            Vector2 wPos = new Vector2(WorldData.WindowWidth / 2 - 25, 275);
            Vector2 sPos = new Vector2(WorldData.WindowWidth / 2 - 76, 400);


            IntroState.Instance.Cat.Draw(WorldData.spriteBatch, new Vector2(WorldData.WindowWidth / 2, 150), new Vector2(0, 3), 0.0f, 5.0f,
                 IntroState.Instance.Flip);


            //WorldData.spriteBatch.DrawString(font, "Move LEFT and RIGHT", new Vector2(5, 50), Color.FromNonPremultiplied(0,255,0,127));
           // WorldData.spriteBatch.DrawString(font, "Jump", new Vector2(550, 50), Color.FromNonPremultiplied(0, 255, 0, 127));

            WorldData.spriteBatch.DrawString(font, "A", aPos + new Vector2(5, 5), Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            WorldData.spriteBatch.DrawString(font, "D", dPos + new Vector2(30, 5), Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            WorldData.spriteBatch.DrawString(font, "W", wPos + new Vector2(20, 2), Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            WorldData.spriteBatch.DrawString(font, "Movement", wPos + new Vector2(-20, 70), Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            WorldData.spriteBatch.DrawString(font, "Press Enter to start the show!", wPos + new Vector2(-100, -50), Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
            WorldData.spriteBatch.DrawString(font, "PUNCH", sPos + new Vector2(35, 2), Color.Black, 0.0f, Vector2.Zero, 0.7f, SpriteEffects.None, 0);

            if( NCurrentButton == 1 )
                WorldData.spriteBatch.Draw(a, aPos, null, Color.Violet, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);
            else
            WorldData.spriteBatch.Draw(a, aPos,null, Color.White,0,Vector2.Zero,.5f,SpriteEffects.None,0);

            if (NCurrentButton == 2)
                WorldData.spriteBatch.Draw(d, dPos, null, Color.Violet, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);
            else
            WorldData.spriteBatch.Draw(d, dPos, null, Color.White, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);

            if (NCurrentButton == 3)
                WorldData.spriteBatch.Draw(w, wPos, null, Color.Violet, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);
            else
            WorldData.spriteBatch.Draw(w, wPos, null, Color.White, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);

            if (NCurrentButton == 4)
                WorldData.spriteBatch.Draw(s, sPos, null, Color.Violet, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);
            else
                WorldData.spriteBatch.Draw(s, sPos, null, Color.White, 0, Vector2.Zero, .5f, SpriteEffects.None, 0);
            //WorldData.spriteBatch.DrawString(font, "A",aPos+new Vector2(10,10), Color.Black);
            //WorldData.spriteBatch.DrawString(font, "D",dPos+new Vector2(10,10), Color.Black);
            //WorldData.spriteBatch.DrawString(font, "W",wPos+new Vector2(10,10), Color.Black);
           // WorldData.spriteBatch.DrawString(font, "'Space Bar'", new Vector2(300, 300), Color.Black);
           // WorldData.spriteBatch.DrawString(font, "Attack", new Vector2(336, 265), Color.FromNonPremultiplied(0, 255, 0, 127));

            Vector2 spacePos = new Vector2(0, 0);
        }
        public override void Enter()
        {
            NCurrentButton = -1;
            CInput.Instance.Clear();
        }
        public override void Exit()
        {
            NCurrentButton = -1;
        }

        //////////////////////////////////////////////////////////////////////////
        // Properties

        public int NCurrentButton
        {
            get { return m_nCurrentButton; }
            set { m_nCurrentButton = value; }
        }

        public int DID
        {
            get { return dID; }
            set { dID = value; }
        }
        public int SID
        {
            get { return sID; }
            set { sID = value; }
        }
        public int AID
        {
            get { return aID; }
            set { aID = value; }
        }
        public int WID
        {
            get { return wID; }
            set { wID = value; }
        }
        public int FightID
        {
            get { return fightID; }
            set { fightID = value; }
        }
        public static GameControlState Instance
        {
            get { return instance; }
        }
        public int FontID
        {
            get { return fontID; }
            set { fontID = value; }
        }
    }
}
